﻿using DotXxlJob.Core;
using XxlJobDotNetCore.Handler;
using XxlJobDotNetCore.RequestBase;
using XxlJobDotNetCore.Services;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace XxlJobDotNetCore.Controller
{
    /// <summary>
    /// 任务测试API
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    public class TestJobController : ControllerBase
    {
        private readonly TestJobService _testJobService;
        private readonly ITestJobRefitRequest _requst;
        public TestJobController(TestJobService testJobService, ITestJobRefitRequest testJobRequest)
        {
            _testJobService = testJobService;
            _requst = testJobRequest;
        }
        /// <summary>
        /// 测试方法
        /// </summary>
        /// <param name="TestStr">测试字符串</param>
        /// <returns></returns>
        [HttpPost("test")]
        public string Test([FromBody]string TestStr)
        {
            return _testJobService.Test(TestStr);
        }
        /// <summary>
        /// 智能停车场接口测试
        /// </summary>
        /// <returns></returns>
        [HttpGet("smartParking")]
        public async Task<object> SmartParkingSync()
        {
            return await _requst.SmartParkingSync();
        }
        /// <summary>
        /// 提示接口测试
        /// </summary>
        /// <returns></returns>
        [HttpGet("zyAlert")]
        public async Task<object> ZyAlertSync()
        {
            return await _requst.ZyAlertSync();
        }
        /// <summary>
        /// 获得全部Handler
        /// </summary>
        /// <returns></returns>
        [HttpGet("getAllHandlerList")]
        public List<string> GetAllHandlerList()
        {
            var allTypes = typeof(TestTaskNetTestHandler).Assembly.GetTypes();
            return allTypes.Where(t => t.BaseType != null && t.BaseType.Equals(typeof(AbstractJobHandler))).Select(x=>x.Name).ToList();
        }
    }
}
